<template>
  <view class="page">
    <u-navbar @leftClick="navLeftClick" :fixed="false" title="设置昵称" placeholder bgColor="#fff"></u-navbar>
    <view class="content">
      <input type="nickname" maxlength="14" v-model="userInfo.nickName" placeholder="请输入昵称"/>
      <view class="btn" @click="submit">确认提交</view>
    </view>
  </view>
</template>

<script>
import { setUserInfo } from '@/api/index'

export default {
  data() {
    return {
      nickName: '',
      userInfo: {},
    };
  },
  onLoad() {
    this.userInfo = uni.getStorageSync('userInfo')
  },
  methods: {
    submit() {
      if(this.userInfo.nickName === '') {
        uni.showToast({
          icon: 'none',
          title: '请输入昵称'
        })
        return
      }
      const that = this
      delete this.userInfo.roles
      setUserInfo(this.userInfo).then(res => {
        uni.showToast({
          icon: 'none',
          title: `修改成功`
        })
        setTimeout(() => {
          that.goBack()
        }, 1000)
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.page {
  width: 750rpx;
  min-height: 100vh;
  background-color: #F5F5F5;
  padding-bottom: 80rpx;
  position: relative;
  .content {
    width: 702rpx;
    margin: 0 auto;
    margin-top: 12rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    input {
      width: 702rpx;
      height: 100rpx;
      background: #FFFFFF;
      border-radius: 12rpx;
      font-size: 28rpx;
      padding-left: 28rpx;
      margin-bottom: 120rpx;
    }
    .btn {
      width: 440rpx;
      height: 90rpx;
      line-height: 90rpx;
      text-align: center;
      background: #56CB03;
      border-radius: 200rpx;
      border: 2rpx solid #56CB03;
      font-size: 28rpx;
      color: #FFFFFF;
    }
  }
}
</style>
